package com.jt9003.controller;


import com.jt9003.pojo.Patient_case_history2;
import com.jt9003.service.patientCaseHistoryService;
import com.jt9003.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
//患者病例模块
@RestController
public class patientCaseHistoryController {

    @Autowired
    patientCaseHistoryService pchs;

    /**
     * 查询所有患者病例
     */
    @RequestMapping("/selectPCH")
    public Map<String,Object> selectPCH(@RequestParam(value = "page",required = false,defaultValue="1")Integer page,
                                        @RequestParam(value = "limit",required = false,defaultValue="5")Integer limit,
                                        @RequestParam(value = "time",required = false)String date,
                                        @RequestParam(value = "patientCaseHistory",required = false)String patientCaseHistory,
                                        @RequestParam(value = "pName",required = false)String pName){
        Map<String,Object> map=new HashMap<String, Object>();
        List<Patient_case_history2> list;
        System.out.println("date:"+date+"========patientCaseHistory:"+patientCaseHistory+"=========pName:"+pName);
        //获取拿到的时间，拆分开
        String start = null;
        String end = null;
        if (date != null && date != "") {
            String[] strarr = date.split(" - ");    //空格不能去掉，需要按照空格进行拆分
            start = strarr[0];
            end = strarr[1];
            map.put("start", start);
            map.put("end", end);
        }
        //分页设置
        int index = PageUtils.getStart(page,limit);
        map.put("pName",pName);
        map.put("patientCaseHistory",patientCaseHistory);
        map.put("index",index);
        map.put("limit",limit);
        int count =0;
        try {
            list=pchs.selectPCH(map);  //查询数据
             count = pchs.selectAllData(map);   //查询数据总数

            if (list.size()>0){
                //查询成功
                map.put("result",list);
                map.put("message","查询成功");
                map.put("success",true);
                map.put("","");
                map.put("code",0);
                map.put("count",count);
            }else{
                map.put("message","查询失败");
                map.put("success",false);
                map.put("","");
                map.put("code",0);
                map.put("count",count);
            }
        }catch(Exception e){
            e.printStackTrace();
            map.put("message","查询程序出现异常");
            map.put("success",false);
            map.put("","");
            map.put("code",0);
            map.put("count",count);
        }
        return map;
    }

}
